package xyz.example.scan;

import org.junit.Test;
import xyz.lwm.lazycat.utility.IoUtil;
import xyz.lwm.lazycat.utility.resource.Resource;
import xyz.lwm.lazycat.utility.scan.ScanUtil;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class ScanResourceTest {

    @Test
    public void test() {
        List<Resource> list = ScanUtil.scanResources("classpath:banner.txt.bak");
        list.stream().findFirst().ifPresent(r -> {
            try (InputStream is = r.getInputStream()) {
                String s = IoUtil.readUtf8(is);
                System.out.println(s);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
    }

    @Test
    public void testPattern() {
        String pattern = "classpath:xyz/lwm/lazycat/**/*.class";
        List<Resource> list = ScanUtil.scanResources(pattern);
        list.forEach(r -> {
            System.out.println(r.getName());
        });
    }

}
